package com.ztjava.core.tool;

import com.jfinal.plugin.redis.Cache;
import com.jfinal.plugin.redis.Redis;
import com.ztjava.core.Constant;
/***
 * 适用于简单场景，复杂场景请使用common-record-repeat
 * @author Administrator
 *
 */
public class RepeatTool {
	//默认一个月过期
	public boolean checkAndSetRepeat(String model,String method,Integer object_id,Integer user_id){
		return checkAndSetRepeat(model, method, object_id, user_id,3600*24*30);
	}
	public boolean checkAndSetRepeat(String model,String method,Integer object_id,Integer user_id,int seconds){
		Cache cache = Redis.use();
		String key = Constant.R_PRE+model+"_"+method+"_"+object_id+"_"+user_id;
		if(cache.exists(key)){
			return false;
		}
		cache.setex(key, seconds, 1);
		return true;
	}
}
